package com.gite.nouette.admin.implementation.view.util;

import com.gite.nouette.admin.contract.view.IVCommand;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;

public class ViewUtil {
	public static String getName(Canvas canvas) {
		return canvas.getTitle();
	}

	public static void setName(String name, Canvas canvas) {
		canvas.setTitle(name);
	}

	public static boolean isActive(Canvas canvas) {
		return !canvas.isDisabled();
	}

	public static void active(Canvas canvas) {
		canvas.enable();
	}

	public static void desactive(Canvas canvas) {
		canvas.disable();
	}

	public static void setActive(boolean active, Canvas canvas) {
		if (active) {
			canvas.enable();
		} else {
			canvas.disable();
		}
	}

	public static ClickHandler createClickHandler(final IVCommand<?> vCommand) {
		return new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				vCommand.getC().execute();
			}
		};
	}
}
